package com.itheima.edu.info.manage.service;

import com.itheima.edu.info.manage.dao.teacherDao;
import com.itheima.edu.info.manage.domain.teacher;

public class teacherService {
    private teacherDao teacherDao = new teacherDao();

    public boolean addTeacher(teacher t) {
        return teacherDao.addTeacher(t);
    }

    public boolean isExist(String id) {
        teacher[] teachers = teacherDao.findAllTeacher();
        boolean exists = false;
        for (int i = 0; i < teachers.length; i++) {
            teacher teacher = teachers[i];
            if (teacher != null && teacher.getId().equals(id)) {
                exists = true;
                break;
            }
        }
        return exists;
    }

    public teacher[] findAllStudent() {
        teacher[] allTeacher = teacherDao.findAllTeacher();
        boolean flag = false;
        for (int i = 0; i < allTeacher.length; i++) {
            teacher t = allTeacher[i];
            if(t!=null){
                flag=true;
                break;
            }
        }
        if(flag){
            return allTeacher;
        }else {
            return null;
        }
    }

    public void deleteTeacherById(String id) {
        teacherDao.deleteTeacherById(id);
    }

    public void updateTeacher(String id, teacher newTeacher) {
        teacherDao.updateTeacher(id,newTeacher);
    }
}
